package com.tnxst.phexamination.public_health_docking_interface;

import com.tnxst.phexamination.constant.Trade;
import com.tnxst.phexamination.dto.DiabetesFollowDTO;
import com.tnxst.phexamination.utils.ReflectUtils;
import com.tnxst.phexamination.utils.StringUtils;
import com.tnxst.phexamination.utils.WebServiceUtils;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 糖尿病接口
 */
public class DiabetesInterface {

    /**
     * 59-1 查询糖尿病随访记录列表
     * @param personId
     * @param pageSize
     * @param pageIndex
     * @param response
     */
    public static void queryDiabetesFollowList(String personId, Integer pageSize,
                                               Integer pageIndex, WebServiceUtils.Response response){
        String trade = Trade.DIABETES.QUERY_DIABETES_FOLLOW_LIST;
        Map<String, Object> data = StringUtils.getPageDataMap(pageSize, pageIndex);
        data.put("PersonId",personId);
        WebServiceUtils.call(trade,data,response);
    }

    /**
     * 59-2 增加或修改糖尿病随访记录
     * @param diabetesFollowDTO
     * @param response
     */
    public static void saveOrUpdateDiabetesFollow(DiabetesFollowDTO diabetesFollowDTO, String orgId, WebServiceUtils.Response response){
        String trade = Trade.DIABETES.SAVE_OR_UPDATE_DIABETES_FOLLOW;
        Map<String, Object> data = StringUtils.getDataMap();
        Map<String, Object> cmDiab = new LinkedHashMap<>();
        Map<String, Object> body = new LinkedHashMap<>();
        Map<String, Object> lifestyle = new LinkedHashMap<>();
        Map<String, Object> organ = new LinkedHashMap<>();
        Map<String, Object> transout = new LinkedHashMap<>();
        data.put("CmDiab",cmDiab);
        data.put("Body",body);
        data.put("Labora",diabetesFollowDTO.getLabora());
        data.put("Lifestyle",lifestyle);
        data.put("Drug",diabetesFollowDTO.getDrug());
        data.put("Insulindrug",diabetesFollowDTO.getInsulindrug());
        data.put("Organ",organ);
        data.put("transout",transout);
        data.put("Other",diabetesFollowDTO.getOther());
        data.put("OrgID",orgId);
        fillDiabetesFollow(diabetesFollowDTO,cmDiab,body,lifestyle,organ,transout);
        WebServiceUtils.call(trade,data,response);

    }

    /**
     * 59-3 查询个人糖尿病随访记录
     * @param id
     * @param response
     */
    public static void queryPersonalDiabetesFollow(String id, WebServiceUtils.Response response){
        String trade = Trade.DIABETES.QUERY_PERSONAL_DIABETES_FOLLOW;
        Map<String, Object> data = StringUtils.getDataMap();
        data.put("ID",id);
        WebServiceUtils.call(trade,data,response);
    }

    /**
     * 填充糖尿病随访数据
     * @param diabetesFollowDTO
     * @param cmDiab
     * @param body
     * @param lifestyle
     * @param organ
     * @param transout
     */
    private static void fillDiabetesFollow(DiabetesFollowDTO diabetesFollowDTO, Map<String, Object> cmDiab,
                                           Map<String, Object> body, Map<String, Object> lifestyle,
                                           Map<String, Object> organ, Map<String, Object> transout){
        String[] cmDiabNames = {"ID","PersonID","FollowUpDate","LowBloodSugarReactions","WayUp","Symptom","ExamBodyOther","NextWeight",
                "NextHeartRate","NextSmoking","NextDailyAlcohol","NextExerciseWeekTimes","NextExerciseWeekMinute","Staple","NextStaple",
                "PsychologicalAdjustment","ComplianceBehavior","MedicationCompliance","AdverseDrugReactions","FuClassification","FollowUpRemarks",
                "NextFollowUpDate","DoctorName","UserID","DoctorID","HealthGuidance"};
        String[] bodyNames = {"BodyTemperature","DorsalisPedisArteryPulse","DorsalisPulseResult","HeartRate","RespiratoryRate",
                "LeftSbp","LeftDbp","RightSbp","RightDbp","Height","Weight","Waistline","Hip","Bmi"};
        String[] lifestyleNames = {"ExerciseFrequency","EachExerciseTime","ExerciseWeekTimes","Smoking","DailyAlcoholIntake"};
        String[] organNames = {"LeftEye","RightEye","LeftEyeVc","RightEyeVc","Hearing","MotorFunction"};
        String[] transoutNames = {"TargetOrgName","TranoutReasons"};
        ReflectUtils.objectToMap(cmDiabNames,diabetesFollowDTO,cmDiab);
        ReflectUtils.objectToMap(bodyNames,diabetesFollowDTO,body);
        ReflectUtils.objectToMap(lifestyleNames,diabetesFollowDTO,lifestyle);
        ReflectUtils.objectToMap(organNames,diabetesFollowDTO,organ);
        ReflectUtils.objectToMap(transoutNames,diabetesFollowDTO,transout);

    }


}
